/*
 * Created on 19.09.2006 by leck
 *
 */
package de.devisnik.eidle.flashlight;

public class Circle extends 
AbstractShape implements IShape {

    int[] itsPoints;

    public Circle(int radius) {
        itsPoints = circle(radius);
    }

    public int[] getPointArray(int centerX, int centerY) {
        int[] pointsCopy = clonePoints(itsPoints);
        translate(pointsCopy, centerX, centerY);
        return pointsCopy;
    }

    private int[] circle(int radius) {
    	if (radius == 0) {
    		return new int[0];
    	}
        int[] polygon = new int[8 * radius + 4];
        // x^2 + y^2 = r^2
        for (int i = 0; i < 2 * radius + 1; i++) {
            int x = i - radius;
            int y = (int) Math.sqrt(radius * radius - x * x);
            polygon[2 * i] = x;
            polygon[2 * i + 1] = y;
            polygon[8 * radius - 2 * i - 2] = x;
            polygon[8 * radius - 2 * i - 1] = -y;
        }
        return polygon;

    }

}
